<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport"
    content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  <meta name="author" content="火星科技 http://mars3d.cn " />
  <meta name="apple-touch-fullscreen" content="yes" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  <meta name="format-detection" content="telephone=no" />
  <meta name="x5-fullscreen" content="true" />
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />

  <!-- 标题及搜索关键字 -->
  <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  <meta
    name="description"
    content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS" />

  <link rel="shortcut icon" type="image/x-icon" href="/img/favicon/favicon.ico" />
  <title>视频2D投射 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

  <!--第三方lib-->
  <script
    type="text/javascript"
    src="/lib/include-lib.js"
    libpath="/lib/"
    include="jquery,layer,toastr,font-awesome,bootstrap,bootstrap-table,bootstrap-checkbox,bootstrap-slider,layer,haoutil,mars3d,es5-widget"></script>

  <link href="/css/style.css" rel="stylesheet" />
  <style>
    .infoview input {
      vertical-align: middle;
      padding-top: 2px;
      padding-bottom: 2px;
    }
  </style>
</head>

<body class="dark">
  <div id="mars3dContainer" class="mars3d-container"></div>

  <!-- 面板 -->
  <div id="toolbar" class="infoview">
    <div>
      图层状态：
      <div class="checkbox checkbox-primary checkbox-inline">
        <input id="enabledShowHide" class="styled" type="checkbox" checked />
        <label for="enabledShowHide"> 显示 </label>
      </div>
      <div class="checkbox checkbox-primary checkbox-inline">
        透明度：
        <input id="opacity" style="width: 80px" />
      </div>
      <div class="checkbox checkbox-primary checkbox-inline">
        <input id="onClickFlyTo" title="视角定位" type="button" class="btn btn-primary" value="定位" />
      </div>
    </div>

    <div>
      图层交互：
      <div class="checkbox checkbox-primary checkbox-inline">
        <input id="enabledPopup" class="styled" type="checkbox" checked />
        <label for="enabledPopup"> 单击Popup </label>
      </div>
      <div class="checkbox checkbox-primary checkbox-inline">
        <input id="enabledTooltip" class="styled" type="checkbox" />
        <label for="enabledTooltip"> 移入Tooltip </label>
      </div>
      <div class="checkbox checkbox-primary checkbox-inline">
        <input id="enabledRightMenu" class="styled" type="checkbox" />
        <label for="enabledRightMenu"> 右键菜单绑定 </label>
      </div>
      <div id="enabledCluster" class="checkbox checkbox-primary checkbox-inline" style="display: table;margin-left: 74px">
        <input id="isCluster" class="styled" type="checkbox" />
        <label for="isCluster"> 是否聚合 </label>
      </div>
    </div>

    <div>
      数据测试：
      <input id="count" type="number" value="10" min="1" max="1000000" step="1" class="form-control"
        style="width: 152px" />条

      <input id="addRandomGraphicByCount" type="button" class="btn btn-primary" value="生成" />
      <input id="onClickClear" type="button" class="btn btn-danger" value="清除" />
    </div>

    <div>
      数据导出：
      <input onclick="expJSONFile()" type="button" class="btn btn-primary" value="导出数据" title="导出图层数据为JSON文件" />

      <input id="btnImpFile" type="button" class="btn btn-primary" value="导入数据" title="打开历史导出的JSON文件图层数据" />
      <input id="input_draw_file" type="file" accept=".json,.geojson" style="display: none" />
    </div>

    <div>
      数据维护：
      <input onclick="startDrawGraphic()" type="button" class="btn btn-primary" value="绘制投射视频" title="在图上绘制新增一个矢量数据" />
      <input onclick="startDrawGraphic2Fn()" type="button" class="btn btn-primary" value="按当前相机投射视频"
        title="在图上绘制新增一个矢量数据" />
      <div id="enabledEdit" class="checkbox checkbox-primary checkbox-inline">
        <input id="hasEdit" class="styled" type="checkbox" />
        <label for="hasEdit"> 是否编辑 </label>
      </div>
    </div>
    <table id="graphicTable"></table>
  </div>

  <div class="infoview infoview-left" id="infoview-left">
    <div class="closeBtn" id="closeBtn">x</div>
    <table class="mars-table">
      <tbody>
        <tr>
          <td>相机位置:</td>
          <td>
            <input id="btnSelCamera" type="button" class="btn btn-info" value="鼠标图上点选(相机位置)" />
          </td>
          <td></td>
        </tr>
        <tr title="内部根据水平张角计算相机fov,存在误差">
          <td>水平张角:</td>
          <td>
            <input id="cameraAngle" />
          </td>
          <td></td>
        </tr>
        <tr title="内部根据水平张角和垂直张角计算相机aspectRatio,存在误差">
          <td>垂直张角:</td>
          <td>
            <input id="cameraAngle2" />
          </td>
          <td></td>
        </tr>
        <tr>
          <td>投射距离:</td>
          <td>
            <input id="cameraDistance" />
          </td>
        </tr>

        <tr>
          <td>四周方向:</td>
          <td>
            <input id="cameraHeading" />
          </td>
          <td><input id="btnSelView" type="button" class="btn btn-info" value="图上点选" /></td>
        </tr>
        <tr>
          <td>俯仰角度:</td>
          <td>
            <input id="cameraPitch" />
          </td>
          <td></td>
        </tr>

        <tr>
          <td>视椎框线:</td>
          <td>
            <div class="checkbox checkbox-info checkbox-inline">
              <input type="checkbox" id="chkDebugFrustum" value="this" name="jiaodu" checked />
              <label for="chkDebugFrustum">显示框线</label>
            </div>
          </td>
          <td></td>
        </tr>
        <tr>
          <td>视频透明度:</td>
          <td>
            <input id="txtMixNum" />
          </td>
          <td></td>
        </tr>
        <tr>
          <td>视频角度</td>
          <td>
            <input id="rotateDeg" />
          </td>
        </tr>
      </tbody>
    </table>

    <input id="btnPlayPause" type="button" class="btn btn-info" value="播放暂停" />
    <input id="btnLocate" type="button" class="btn btn-info" value="返回相机视点" />
    <input id="btnConsoleJson" type="button" class="btn btn-info" value="打印参数" />
  </div>

  <video id="trailer" style="display: none" muted="muted" autoplay="autoplay" loop="loop" crossorigin="" controls="">
    <source src="//data.mars3d.cn/file/video/duimian.mp4" type="video/mp4" />
  </video>

  <script src="/js/common.js"></script>
  <script src="/js/graphic_layer_state.js"></script>

  <script src="./map.js"></script>

  <script type="text/javascript">
    "use script" //开发环境建议开启严格模式

    const video = {
      ckdFrustum: true,
      cameraAngle: 0,
      cameraAngle2: 0,
      distanceValue: 0,
      heading: 0,
      pitchValue: 0,
      opacity: 1,
      videoRotate: 0
    }
    let showLeft = false

    function initUI(options) {
      bindAttributePannel()
      $("#infoview-left").hide()
      setTimeout(() => {
        if (graphicLayer) {
          $("#enabledShowHide").attr("checked", graphicLayer.show)
          $("#enabledPopup").attr("checked", graphicLayer.hasPopup())
          $("#enabledTooltip").attr("checked", graphicLayer.hasTooltip())
          $("#enabledRightMenu").attr("checked", graphicLayer.hasContextMenu())

          const graphics = graphicLayer.getGraphics()
          if (graphics.length > 0) {
            if (!graphics[0].hasOpacity) {
              $("#enabledOpacity").hide()
            }
            if (!graphics[0].hasEdit) {
              $("#enabledEdit").hide()
            }
            if (!graphics[0].hasCluster) {
              $("#enabledCluster").hide()
            }
          }
          getGraphic(graphics[0].id)

          graphicLayer.on(mars3d.EventType.addGraphic, function (event) {
            setTimeout(() => {
              getGraphic(event.graphic.id)
            }, 50)
          })
        }
      }, 500)

      // 图层状态
      $("#enabledShowHide").change(function () {
        let val = $(this).is(":checked")
        graphicLayer.show = val
      })
      // 透明度滑动条
      $("#opacity")
        .slider({ min: 0.0, max: 1.0, step: 0.1, value: 1 })
        .on("change", (e) => {
          if (e?.value) {
            graphicLayer.opacity = e.value.newValue
          }
        })
      $("#onClickFlyTo").click(function () {
        graphicLayer.flyTo()
      })

      // 图层交互
      $("#enabledPopup").change(function () {
        let val = $(this).is(":checked")

        if (val) {
          bindLayerPopup() //map.js中不绑定Popup,可以使用graphic_layer_state.js中的bindLayerPopup2
        } else {
          graphicLayer.unbindPopup()
        }
      })
      $("#enabledTooltip").change(function () {
        let val = $(this).is(":checked")

        if (val) {
          graphicLayer.bindTooltip(
            function (event) {
              const attr = getAttrForEvent(event)
              attr["类型"] = event.graphic?.type
              attr["来源"] = "我是layer上绑定的Toolip"
              attr["备注"] = "我支持鼠标移入交互"

              return mars3d.Util.getTemplateHtml({ title: "矢量图层", template: "all", attr: attr })
            },
            { pointerEvents: true }
          )
        } else {
          graphicLayer.unbindTooltip()
        }
      })
      $("#enabledRightMenu").change(function () {
        let val = $(this).is(":checked")

        if (val) {
          bindLayerContextMenu() //map.js中不绑定ContextMenu,可以使用graphic_layer_state.js中的bindLayerContextMenu2
        } else {
          graphicLayer.unbindContextMenu(true)
        }
      })
      $("#isCluster").change(function () {
        let val = $(this).is(":checked")
        graphicLayer.clusterEnabled = val
      })

      // 数据维护
      $("#hasEdit").change(function () {
        let val = $(this).is(":checked")
        if (val && showLeft) {
          $("#infoview-left").show()
          showLeft = true
        } else {
          $("#infoview-left").hide()
          showLeft = true
        }

        // 编辑时，为了方便操作自动关闭Popup，真实项目中请按需修改
        $("#enabledPopup").attr("checked", !val)
        $("#enabledPopup").change()
      })

      // 数据测试 - 生成和清除
      $("#addRandomGraphicByCount").click(function () {
        addRandomGraphicByCount($("#count").val())
        refreshTabelFn()
        graphicLayer.flyTo({ duration: 0, heading: 0, pitch: -40, scale: 1.2 })
      })
      $("#onClickClear").click(function () {
        graphicLayer.clear()
        $("#infoview-left").hide()
        dynamicRiver = null
      })

      $("#btnImpFile").click(function () {
        $("#input_draw_file").click()
      })

      $("#input_draw_file").change(function (e) {
        let file = this.files[0]
        onClickImpFile(file)
      })

      bindEvnet()
    }

    function bindEvnet() {
      $("#cameraAngle")
        .slider({ min: 1, max: 60, step: 0.1, value: video.cameraAngle })
        .on("change", (e) => {
          video.cameraAngle = e.value.newValue
          onChangeAngle(e.value.newValue)
        })
      $("#cameraAngle2")
        .slider({ min: 10, max: 30, step: 0.1, value: video.cameraAngle2 })
        .on("change", (e) => {
          if (e?.value) {
            video.cameraAngle2 = e.value.newValue
            onChangeAngle2(e.value.newValue)
          }
        })
      $("#cameraDistance")
        .slider({ min: 1, max: 1000, step: 0.1, value: video.distanceValue })
        .on("change", (e) => {
          if (e?.value) {
            video.distanceValue = e.value.newValue
            onChangeDistance(video.distanceValue)
          }
        })

      $("#cameraHeading")
        .slider({ min: 0, max: 360, step: 0.1, value: video.heading })
        .on("change", (e) => {
          if (e?.value) {
            video.heading = e.value.newValue
            onChangeHeading(e.value.newValue)
          }
        })

      $("#cameraPitch")
        .slider({ min: -180, max: 180, step: 0.1, value: video.pitch })
        .on("change", (e) => {
          if (e?.value) {
            video.pitchValue = e.value.newValue
            onChangePitch(video.pitchValue)
          }
        })

      $("#txtMixNum")
        .slider({ min: 0, max: 1, step: 0.1, value: video.opacity })
        .on("change", (e) => {
          if (e?.value) {
            video.opacity = e.value.newValue
            onChangeOpacity(e.value.newValue)
          }
        })

      $("#rotateDeg")
        .slider({ min: 0, max: 360, step: 1, value: 0 })
        .on("change", (e) => {
          if (e?.value) {
            video.videoRotate = e.value.newValue
            rotateDeg(video.videoRotate)
          }
        })

      $("#chkDebugFrustum").change(function () {
        let val = $(this).is(":checked")
        video.showFrustum = val
        showFrustum(video.showFrustum)
      })

      $("#btnSelCamera").click(function () {
        selCamera()
      })

      $("#btnSelView").click(function () {
        onClickSelView()
      })

      $("#btnLocate").click(function () {
        locate()
      })

      $("#closeBtn").click(function () {
        lastGraphic && lastGraphic.stopEditing()
        $("#infoview-left").hide()
      })

      $("#btnConsoleJson").click(function () {
        printParameters()
      })

      $("#btnPlayPause").click(function () {
        playOrpause()
      })
    }

    eventTarget.on("loadVideo", (e) => {
      const data = e.value
      video.ckdFrustum = data.ckdFrustum
      video.cameraAngle = data.cameraAngle
      video.cameraAngle2 = data.cameraAngle2
      video.distanceValue = data.distanceValue
      video.pitchValue = data.pitchValue
      video.opcity = data.opcity
      video.heading = data.heading
    })

    let lastGraphic
    setTimeout(() => {
      graphicLayer.on(mars3d.EventType.click, function (event) {
        lastGraphic && lastGraphic.stopEditing()
        lastGraphic = event.graphic
        lastGraphic.startEditing()
        if (showLeft) {
          $("#infoview-left").show()
        }
      })
    }, 100)

    function startDrawGraphic2Fn() {
      const graphic = startDrawGraphic2()
      refreshTabelFn()
    }

    function refreshTabelFn() {
      setTimeout(() => {
        refreshTabel(graphicLayer)
      }, 100)
    }
  </script>
</body>

</html>
